package ch.zbw.pra.sysventory.application.controller;

import java.io.Serializable;
import java.util.List;

import ch.zbw.pra.sysventory.dataaccess.dataAccessObject.ComputerDataAccessObject;
import ch.zbw.pra.sysventory.model.Computer;

/**
 * Controller für die gesammelten Computer
 * 
 * @author Ralph Koster
 */

public class ComputerController implements Serializable {

	private static final long serialVersionUID = -5440126949273275692L;
	
	private ComputerDataAccessObject computerDataAccessObject;
	private List<Computer> computers;

	public ComputerController() {
		this.computerDataAccessObject = new ComputerDataAccessObject();
	}

	public List<Computer> loadComputers() {
		computers = computerDataAccessObject.getAllComputerFromDatabase();
		return computers;
	}

	public Computer getComputerById(String computerId) {
		Computer computer = new Computer();
		if (null != computers && computers.size() != 0) {
			for (Computer tempComputer : computers) {
				if (computerId
						.equals(String.valueOf(tempComputer.getId()))) {
					computer = tempComputer;
				}
			}
		}
		return computer;
	}
}
